﻿using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using PlanningGIS.Framework;
using ESRI.ArcGIS.ADF.BaseClasses;
using PlanningGIS.Win.Controls;
using System;

namespace PlanningGIS.Raster
{
    /// <summary>
    /// 描述：栅格数据查询
    /// 作者：盛琦
    /// 编写日期:2013-10-28
    /// </summary>
    public class RasterQryCmd : BaseCommand
    {
        /// <summary>
        /// 主框架
        /// </summary>
        IApplication m_Application = null;

        FrmRasterQry myform;

        /// <summary>
        /// 构造函数
        /// </summary>
        public RasterQryCmd()
        {
            base.m_caption = "栅格数据查询";
            base.m_toolTip = base.m_caption;
        }
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="hook"></param>
        public override void OnCreate(object hook)
        {
            if (m_Application == null)
            {
                m_Application = hook as IApplication;
            }
        }
        /// <summary>
        /// 点击事件
        /// </summary>
        public override void OnClick()
        {
            try
            {
                if ((m_Application as IFramework).IsMapCtrlactive)
                {
                    if (myform == null || myform.IsDisposed)
                    {
                        myform = new FrmRasterQry();
                        myform.Map = m_Application.Document.get_Map(0);
                    }
                    myform.Visible = false;
                    myform.Show((m_Application as IFramework).MdiForm);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.ShowErrorMsgbox("查询失败：" + ex.Message);
            }
        }
        /// <summary>
        /// 图标
        /// </summary>
        public override int Bitmap
        {
            get
            {
                string bitmapResourceName = "PlanningGIS.Raster.Resources." + this.GetType().Name + ".ico";
                System.IO.Stream pStream = GetType().Assembly.GetManifestResourceStream(bitmapResourceName);
                if (pStream == null) return 0;
                return new Bitmap(pStream).GetHbitmap().ToInt32();
            }
        }
        /// <summary>
        /// 是否可用
        /// </summary>
        public override bool Enabled
        {
            get
            {
                if (m_Application == null)
                    return false;
                return (m_Application as IFramework).IsMapCtrlactive;
            }
        }
    }
}